package com.wanwu.channel.common.vo;

import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.io.Serializable;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;

/**
 * 功能描述：查询定时任务参数
 *
 * @author jcshangguan
 * @version 1.0.0
 * @date 2020/5/11 3:43 下午
 */
@Data
public class QueryJobHandlerReq implements Serializable {

    /**
     * 每次的执行量，最大100
     */
    protected Long count;
    /**
     * 批次量，最大100
     */
    protected Integer batchCount;
    /**
     * 每批的睡眠时间，默认2，单位秒
     */
    protected Integer sleep;
    /**
     * 启示时间，默认当前时间的2天前
     */
    protected Date beginDate;
    /**
     * 结束时间，默认当前时间
     */
    protected Date endDate;
    /**
     * 渠道集合
     */
    protected List<Integer> channels;

    protected List<String> thirdStatus;

    public Long getCount() {
        if (count == null || count > 100 || count <= 0) {
            count = 100L;
        }
        return count;
    }

    public Integer getBatchCount() {
        if (batchCount == null || batchCount > 100 || batchCount <= 0) {
            batchCount = 100;
        }
        return batchCount;
    }

    public Integer getSleep() {
        if (sleep == null || sleep <= 0) {
            sleep = 2;
        }
        return sleep;
    }

    public Date getBeginDate() {
        if (beginDate == null) {
            beginDate = Date.from(getEndDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()
                    .minusDays(2).atZone(ZoneId.systemDefault()).toInstant());
        }
        return beginDate;
    }

    public Date getEndDate() {
        if (endDate == null) {
            endDate = new Date();
        }
        return endDate;
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
    }
}
